(SST) ShlWAPI.pas Version 1.08

Developer Reference
(SST)ShlWAPI PathFindExtension Function
Locates the file extension of the last name component in a path, if present.
Scope
Global (i.e. this function can be called/accessed from code in any unit that includes/uses (SST)ShlWAPI.pas).
Syntax
function PathFindExtension(pszPath : LPCSTR) : LPSTR;
Parameters
pszPath [in] Pointer to a null-terminated, path string, with a length that does not exceed MAX_PATH (= 260) ANSI or Uicode characters (including the terminating, single or double byte, null character).
Return Values
If the function succeeds, it returns a pointer to the last period in the last hame component of the path string. Otherwise, the function returns NIL.
Remarks
The function fails, if the path string is terminated by a DOS/Windows path delimiter (i.e. a backslash). But, it does not appear to fail, if the path components are separated and terminated by a Unix style path delimiter (i.e. a "/").
The function is also capable of handling Unix style (i.e. slash instead of backslash) path delimiters.
With the exception of the limit on the length of the input string, this function is essentially identical to the Delphi SDK function ExtractFileExt.
Example
PROCEDURE TForm4.TestShlWAPIPathFindExtension(Sender : TObject); VAR fullpath : STRING; VAR filecomponentp : PChar; VAR newinfoline : STRING; BEGIN fullpath := ''; filecomponentp := NIL; newinfoline := ''; fullpath := 'WinWordDocument.doc'; newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := 'C:\Hello\Windows\World\WinApplication.exe'; newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := 'C:\Hello\Windows\World\Win.Application.exe'; newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := 'C:\Hello\Windows\World\Win Application.exe'; newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := 'C:\Hello\Windows\World\Folder.With.Periods\WinApplication.exe'; newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := 'C:\Hello\Windows\World\Folder.With.Periods\WinFileNoSuffix'; newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := 'C:\Hello\Windows\World\Folder.With.Periods\FileOrFolderNoSuffix\'; newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := 'C:\Hello\Windows\World\Folder.With.Periods\Invalid:CharInName*.Suffix\'; newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := 'C:\Hello\Windows\World\Win Application.exe\'; newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := 'C:\'; newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := 'C:'; newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := '\\UNCSERVER\'; newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := '\\UNCSERVER\Hello\Windows\World\Win.Application.exe'; newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := 'D:/Hello/Unix/World/WinApplication.exe'; newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := 'D:/Hello/Unix/World/UnixApplication.o/'; newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := 'D:/Hello/Unix/World/UnixScript.php/'; newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := ''; //Empty string newinfoline := 'PathFindExtension called with: ' + fullpath; Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(PChar(fullpath)); IF ((filecomponentp <> NIL) AND (filecomponentp^ <> #0)) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); fullpath := ''; newinfoline := 'PathFindExtension called with: NIL'; //NIL Memo1.Lines.Add(newinfoline); filecomponentp := PathFindExtension(NIL); IF (filecomponentp <> NIL) THEN newinfoline := filecomponentp ELSE newinfoline := 'NIL'; Memo1.Lines.Add(newinfoline); Memo1.Lines.Add(''); END;
The above example code produces the following output:
PathFindExtension called with: WinWordDocument.doc .doc PathFindExtension called with: C:\Hello\Windows\World\WinApplication.exe .exe PathFindExtension called with: C:\Hello\Windows\World\Win.Application.exe .exe PathFindExtension called with: C:\Hello\Windows\World\Win Application.exe .exe PathFindExtension called with: C:\Hello\Windows\World\Folder.With.Periods\WinApplication.exe .exe PathFindExtension called with: C:\Hello\Windows\World\Folder.With.Periods\WinFileNoSuffix NIL PathFindExtension called with: C:\Hello\Windows\World\Folder.With.Periods\FileOrFolderNoSuffix\ NIL PathFindExtension called with: C:\Hello\Windows\World\Folder.With.Periods\Invalid:CharInName*.Suffix\ NIL PathFindExtension called with: C:\Hello\Windows\World\Win Application.exe\ NIL PathFindExtension called with: C:\ NIL PathFindExtension called with: C: NIL PathFindExtension called with: \\UNCSERVER\ NIL PathFindExtension called with: \\UNCSERVER\Hello\Windows\World\Win.Application.exe .exe PathFindExtension called with: D:/Hello/Unix/World/WinApplication.exe .exe PathFindExtension called with: D:/Hello/Unix/World/UnixApplication.o/ .o/ PathFindExtension called with: D:/Hello/Unix/World/UnixScript.php/ .php/ PathFindExtension called with: NIL PathFindExtension called with: NIL NIL
Requirements
Unit: Declared and imported in (SST)ShlWAPI.pas
Library: (SST)ShlWAPI.dcu/(SST)ShlWAPI.obj
Unicode: Implemented as ANSI (PathFindExtension and PathFindExtensionA) and Unicode (PathFindExtensionW) functions.
Min. ShlWAPI.dll version according to MS SDK doc.: 4.71
Min. ShlWAPI.dll version based on SST research: 4.71
Min. OS version(s) according to Microsoft SDK doc.: Windows 2000, Windows NT 4.0 with Internet Explorer 4.0, Windows 98, Windows 95 with Internet Explorer 4.0
Min. OS version(s) according to SST research.: Windows NT 4.0 with IE 4.0, Windows 95 with IE 4.0, Windows 98, Windows 2000 and later
See Also
PathFindFileName, PathFindNextComponent, PathFindSuffixArray, PathGetArgs
 
Windows APIs: PathFindExtension, PathFindFileName, PathFindNextComponent, PathFindSuffixArray, PathGetArgs


Document/Contents version 1.00
Page/URI last updated on 07.12.2023
 
Copyright © Stoelzel Software Technologie (SST) 2010 - 2015
Suggestions and comments mail to:
webmaster@stoelzelsoftwaretech.com